package org.linlinjava.litemall.admin.service;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.qcode.QCodeService;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.ILiquormallLiquor;
import org.linlinjava.litemall.db.domain.IliquormallTopic;
import org.linlinjava.litemall.db.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.*;

@Service
public class AdminLiquorService {
    private final Log logger = LogFactory.getLog(AdminLiquorService.class);

    @Autowired
    private ILiquormallLiquorService liquorService;

    public Object list(String title, Integer page, Integer limit, String sort, String order) {
        List<ILiquormallLiquor> liquorList = new ArrayList<>();
        if (StringUtils.isEmpty(title)) {
            liquorList = liquorService.queryList(page, limit);
        } else {
            liquorList = liquorService.queryListByTitle(title, page, limit);
        }
        return ResponseUtil.okList(liquorList);
    }

    /**
     * 删除酒友圈
     *
     * @param liquor
     * @return
     */
    @Transactional
    public Object delete(ILiquormallLiquor liquor) {
        Integer id = liquor.getId();

        if (id == null) {
            return ResponseUtil.badArgument();
        }

        if (liquorService.deleteLiquor(id) == 0) {
            return ResponseUtil.fail();
        }

        return ResponseUtil.ok();

    }


}
